package com.health.httpbean.format;

import android.text.TextUtils;

import com.health.tablebean.BD_DD_INFO;

import java.util.ArrayList;
import java.util.List;

/**
 * author : xiaoxin
 * date   : 2020/12/17 9:27
 * desc   :
 * update :
 */
public class FormatUtils {

    public static String parseString(String filedVal) {
        if (TextUtils.isEmpty(filedVal)) {
            return filedVal;
        }
        if (filedVal.startsWith("DM") && filedVal.contains(",")) {
            String[] split = filedVal.split(",");
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < split.length; i++) {
                if (i == split.length -1) {
                    stringBuilder.append(split[i].substring(split[i].lastIndexOf("_") + 1));
                } else {
                    stringBuilder.append(split[i].substring(split[i].lastIndexOf("_") + 1)+",");
                }
            }
            return stringBuilder.toString();
        } else {
            return filedVal.substring(filedVal.lastIndexOf("_") + 1);
        }
    }

    public static Integer parseInt(String data) {
        try {
            if (TextUtils.isEmpty(data)) {
                return 0;
            }
            if (data.startsWith("DM")) {
                return Integer.parseInt(data.substring(data.lastIndexOf("_") + 1));
            } else {
                return Integer.parseInt(data);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static double parseDouble(String data) {
        try {
            if (TextUtils.isEmpty(data)) {
                return 0.0;
            }
            if (data.startsWith("DM")) {
                return Double.parseDouble(data.substring(data.lastIndexOf("_") + 1));
            } else {
                return Double.parseDouble(data);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return 0.0;
        }
    }

    /**
     * 转换 AskSymptom 字段字典类型
     * @param askSymptom 病症字段数据  DM04-02_R51.x,DM04-02_R11.x,DM04-02_R00.2
     * @param askSymptom 病症字段 数据库数据
     * @return
     */
    public static String formatAskSymptom(String askSymptom,List<BD_DD_INFO> list) {
        if (TextUtils.isEmpty(askSymptom)) {
            return null;
        }
//        String json = AssetUtil.getJson("GxySymptom.json", NovaApplication.getInstance());
//        List<AskSymptomBean> list = GsonUtils.fromJson(json, new TypeToken<List<AskSymptomBean>>() {
//        }.getType());
        String[] split = askSymptom.split(",");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < split.length; i++) {
            for (BD_DD_INFO askSymptomBean : list) {
                if (split[i].equals(askSymptomBean.getID())) {
                    if (i == split.length - 1) {
                        stringBuilder.append(askSymptomBean.getSORT());
                    } else {
                        stringBuilder.append(askSymptomBean.getSORT() + ",");
                    }
                    break;
                }
            }
        }
        return stringBuilder.toString();
    }

    /**
     * 药品用法
     * @param position
     * @return
     */
    public static String cycle(int position) {
        List<String> ylList = new ArrayList<String>();
        ylList.add("一日两次");
        ylList.add("一周两次");
        ylList.add("睡前服用");
        ylList.add("12小时一次");
        ylList.add("1小时一次");
        ylList.add("3小时一次");
        ylList.add("6小时一次");
        ylList.add("一日三次");
        ylList.add("一日一次");
        ylList.add("一日四次");
        ylList.add("隔日一次");
        ylList.add("一周一次");
        ylList.add("一周两次");
        ylList.add("立即服用");
        ylList.add("其他");
        if (position > ylList.size()) {
            return  ylList.get(ylList.size() - 1);
        }
        return ylList.get(position);
    }

    /**
     * 药品用途
     * @return
     */
    public static String drugMethod(int position) {
        List<String> ccList = new ArrayList<String>();
        ccList.add("口服");
        ccList.add("直肠用药");
        ccList.add("舌下用药");
        ccList.add("注射用药");
        ccList.add("吸入用药");
        ccList.add("局部用药");

        ccList.add("皮下注射");
        ccList.add("皮内注射");
        ccList.add("其它途径");
        ccList.add("滴眼");
        ccList.add("喷喉");
        ccList.add("滴鼻");
        ccList.add("含化");
        ccList.add("敷伤口");
        ccList.add("擦皮肤");
        ccList.add("胸膜腔用药");
        ccList.add("腹腔用药");
        ccList.add("阴道用药");
        ccList.add("推管内用药");
        ccList.add("气管内用药");

        ccList.add("关节腔内用药");
        ccList.add("肌肉注射");
        ccList.add("静脉注射或静脉滴注");
        ccList.add("其他局部用药");
        if (position > ccList.size()) {
            return  ccList.get(ccList.size() - 1);
        }
        return ccList.get(position);
    }


}
